package com.pengtu.gsj.controller.lzgl;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.lzgl.Budget;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.lzgl.BudgetService;

@Controller
@RequestMapping("budget")
public class BudgetController extends DefaultBaseController{
	@Autowired
	private BudgetService budgetService;
	
	
	
	/**
	/**
	 * 加载
	 * @param id
	 * @return
	 */
	@ModelAttribute
	public Budget load(String id){
		Budget budget;
		if(StringUtils.isNotEmpty(id)){
			budget = budgetService.getBudget(id);
		}else{
			budget = new Budget();
		}
		return budget;
	}
	
	
	/**
	 * 页面跳转
	 * @return
	 */
	@RequestMapping("listInfo")
	@Token(save = true)
	public String showLisfInfo() {
		return "lzgl/budget_list";
	}
	
	
	@RequestMapping(value="list", produces = "application/json; charset=utf-8")
	@ResponseBody
	public Page<Budget> getRoadMaterialList(Page<Budget> page, HttpServletRequest request){
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("year");
			page.setOrder(Page.ASC);
		}
		page = budgetService.findBudget(page,queryFilter);
		return page;
	}
	
	/**
	 * 保存
	 * @param budget
	 * @return
	 */
	@RequestMapping(value = "save", method=RequestMethod.POST)
	@ResponseBody
	@Token(remove = true)
	public boolean saveBudget(@ModelAttribute Budget budget){
		budgetService.saveBudget(budget);
		return true;
	}
	
	
	/**
	 * 加载数据
	 * @param budget
	 * @return
	 */
	@RequestMapping(value="show")
	@ResponseBody                                                     
	public Budget showBudget (@ModelAttribute Budget budget){
		return budget;
	}
	
	/**
	 * 删除
	 * @param budget
	 * @return
	 */
	@RequestMapping(value="delete")
	@ResponseBody
	public boolean delateInfoManagement(@ModelAttribute Budget budget){
		budgetService.delateBudget(budget);
		return true;
	}
	
}
